package com.yzc.controller;

import com.yzc.model.DTO.FlightOrderDetail;
import com.yzc.model.vo.page.PageResult;
import com.yzc.model.vo.ticket_order.FlightOrderVo;
import com.yzc.result.Result;
import com.yzc.service.TicketFlightOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/ticketOrder/flight")
public class TicketFlightOrderController {

    @Autowired
    private TicketFlightOrderService service;

    @PostMapping("/create")
    public Result<Void> createOrder(@RequestBody FlightOrderDetail flight) {
        service.createTicketOrder(flight);
        return Result.success();
    }

    @GetMapping("/users/{userId}/{pageNo}/{pageSize}")
    public Result<PageResult<FlightOrderVo>> listOrders(
            @PathVariable("userId") Long userId,
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize
    ) {

        PageResult<FlightOrderVo> pageResult = service.listOrders(userId, pageNo, pageSize);
        return Result.success(pageResult);
    }

    @PostMapping("/pay")
    public Result<String> payOrder(@RequestParam("orderId") Long orderId, @RequestParam("paymentMethod") String paymentMethod) {
        return service.payOrder(orderId, paymentMethod);
    }
}
